package com.jsb.laundry.common.response;

import com.github.pagehelper.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.ArrayList;
import java.util.List;

/**
 * 自定义page返回格式
 */
@ApiModel(description = "分页对象")
public class ResultPage<T> {

    //当前页
    @ApiModelProperty("当前页")
    private int pageNum;
    // 页大小
    @ApiModelProperty("页大小")
    private int pageSize;

    //总数量
    @ApiModelProperty("总数量")
    private long total;

    // 数据
    @ApiModelProperty("数据")
    private List<T> list;

    public ResultPage(T t) {
        if (t instanceof Page) {
            Page page = (Page) t;
            this.pageNum = page.getPageNum();
            this.pageSize = page.getPageSize();
            this.total = page.getTotal();
            this.list = new ArrayList<>();
            this.list.addAll(page.getResult());
        }
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }
}
